import { makeUnEnumerable } from '../util'

export class VNode {
  class
  name
  frame
  subViews

  constructor (options, parent, index) {
    Object.assign(this, options)
    this.class = options.tag || options.class
    this.name = genName(options.name, parent, index)

    makeUnEnumerable(this, '_parent', parent)
    makeUnEnumerable(this, '_options', options)

    this.events = undefined
    if (options.subViews) this.subViews = options.subViews.map((child, i) => new VNode(child, this, i))
  }

  $ref = null
}

function genName (name, parent, index) {
  if (name != undefined) return name
  let str = ''
  if (!parent) return 'root'
  str += parent.class
  if (parent.name) str += parent.name
  str += index
  return str
}
